package com.lukk.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.lukk.dao.TerritoryDAO;
import com.lukk.pojo.Territory;
import com.lukk.service.TerritoryService;

@Service("territoryService")
@Transactional(readOnly =true)
public class TerritoryServiceImpl implements TerritoryService {
	@Autowired
	private TerritoryDAO territoryDAO;

	public TerritoryDAO getTerritoryDAO() {
		return territoryDAO;
	}

	public void setTerritoryDAO(TerritoryDAO territoryDAO) {
		this.territoryDAO = territoryDAO;
	}

	@Override
	public List<Territory> findAllProvince(Integer level) {

		return territoryDAO.selectAllProvince(level);

	}

	@Override
	public List<Territory> findAllCity(String parentId) {
		return territoryDAO.selectAllCity(parentId);
	}

	@Override
	public List<Territory> findAllCountry(String code) {
		return territoryDAO.findAllCountry(code);
	}
	@Transactional(readOnly =false, propagation = Propagation.REQUIRES_NEW)
	@Override
	public boolean isCovered(String name) {
		Integer count = territoryDAO.selectCountByName(name);
		if (count > 0) {
			return true;
		}
		return false;
	}

}
